home *** CD-ROM | disk | FTP | other *** search
/ Amiga News 96 / Amiga News 96.iso / amig_ad_os / avm / avminstall / rexx / silentanswer.avm < prev    next >
Text File  |  1977-12-31  |  12KB  |  493 lines

  1. /* TITLE: avm:rexx/silentanswer.avm */
  2. /* we want results! Otherwise, we wouldn't get anything from RESULT */
  3. options results
  4.  
  5. /* Need to make sure that stdtail.avm is also included */
  6. signal on halt
  7. signal on novalue
  8. signal on syntax
  9. signal on break_c
  10.  
  11. /* needed for some of the functions we use */
  12. call addlib("rexxsupport.library", 0, -30, 0)
  13.  
  14. /* a higher than normal priority since calls are important to us :) */
  15. call pragma('priority', 1)
  16.  
  17. /* ensure that commands are directed to the correct server */
  18. parse arg servername .
  19. address value servername
  20.  
  21.  
  22. parse arg servername faxscript datascript distinctivering 'CID$' acidname '$' acidnumber '$'
  23. call setclip(address() || 'CIDNAME', acidname)
  24. call setclip(address() || 'CIDNUMBER', acidnumber)
  25.  
  26. /* Initialize log entry */
  27.  
  28. handle = makeUniqueFile()
  29. call initLogEntry()
  30. log.type = 'Silent'
  31. mailbox = 'silent'
  32.  
  33. /* Put beep in here if you want */
  34.  
  35. readkeyagain:
  36. 'readnkeys' '1' '90'
  37. a_=rc
  38. if a_=0 then value=result
  39. if 0 then nop
  40. else if a_=0 then signal possiblechoice
  41. else if a_=4 then signal stdfax
  42. else if a_=5 then signal stddata
  43. else if a_=12 then signal stdabort
  44. else if a_=14 then signal stderror
  45. else if a_=16 then signal stderror
  46.  
  47. /* Put another beep in here if you want */
  48.  
  49. finished:
  50. /* Save log entry */
  51.  
  52. log.comment = ''
  53. log.origMailbox = mailbox
  54. call saveLogEntry(mailbox, handle)
  55. exit
  56.  
  57. possiblechoice:
  58. select
  59.   when value = '2' then signal stdfax
  60.   when value = '1' then signal dorecord
  61.   when value = '5' then signal stddata
  62.   when value = '*' then signal stdabort
  63.   otherwise nop
  64. end
  65. signal finished
  66.  
  67. dorecord:
  68. call time('r')
  69.  
  70. 'recordvoice' '120' '-1' '-1' handle
  71. a_=rc
  72. if 0 then nop
  73. else if a_=4 then signal stdfax
  74. else if a_=5 then signal stddata
  75. else if a_=12 then signal stdabort
  76. else if a_=14 then signal stderror
  77. else if a_=16 then signal stderror
  78.  
  79. log.type = 'Voice'
  80. log.length = trunc(time('e'))
  81. log.filename = handle
  82. signal finished
  83.  
  84. /* TITLE: avm:rexx/simplestdtail.avm */
  85. /* This is the standard tail */
  86. exit
  87.  
  88. exit
  89.  
  90. mailboxDir: procedure
  91.     parse arg mailbox
  92.  
  93.     return 'avmmbox:' || mailbox || '/'
  94.  
  95. logFile: procedure
  96.     parse arg mailbox, magiccookie
  97.  
  98.     return 'avmmbox:' || mailbox || '/logs/' || magiccookie
  99.  
  100. voiceFile: procedure
  101.     parse arg mailbox, magiccookie
  102.  
  103.         if (verify(magiccookie, '/:', 'M') = 0) then
  104.           return 'avmmbox:' || mailbox || '/voices/' || magiccookie
  105.         else
  106.           return magiccookie
  107.  
  108. makeUniqueFile: procedure
  109.     if arg() ~= 0 then do
  110.         rc = "makeUniqueFile: bad args"
  111.         signal error
  112.     end
  113.     return address() || '.' || date('i') || '.' || time('s') || '.' || random(1, 999, time('s'))
  114.  
  115. convertToDate: procedure
  116.     if arg() ~= 1 then do
  117.         rc = "convertToDate: bad args"
  118.         signal error
  119.     end
  120.     parse arg timeInC
  121.  
  122.     actualTime = (timeInC - (2922)*86400) // (86400)
  123.     actualDate = (timeInC - actualTime - 2922*86400) % 86400
  124.  
  125.     return actualDate /* returning it in 'internal' format */
  126.  
  127. convertToTime: procedure
  128.     if arg() ~= 1 then do
  129.         rc = "convertToTime: bad args"
  130.         signal error
  131.     end
  132.     parse arg timeInC
  133.     
  134.     actualTime = (timeInC - (2922)*86400) // (86400)
  135.  
  136.     return actualTime
  137.  
  138. cTime: procedure
  139.     /* 2922 = 8*365 + 2 */
  140.     /* 86400 = 24*60*60 */
  141.     return (date('i')+2922)*86400 + time('s')
  142.  
  143. /* this returns a handle that you must use after initializing log. */
  144. initLogEntry: procedure expose log.
  145.     if arg() ~= 0 then do
  146.         rc = "initLogEntry: bad args"
  147.         signal error
  148.     end
  149.     
  150.     drop log.
  151.         log. = ''
  152.  
  153.         acidname = getclip(address() || 'CIDNAME')
  154.         acidnumber = getclip(address() || 'CIDNUMBER')
  155.  
  156.     /* 2922 = 8*365 + 2 */
  157.     /* 86400 = 24*60*60 */
  158.     log.time = (date('i')+2922)*86400 + time('s')
  159.     log.cidname = acidname
  160.     log.cidnumber = acidnumber
  161.  
  162.     return
  163.  
  164. loadLogEntry: procedure expose log.
  165.     if arg() ~= 2 then do
  166.         rc = "loadLogEntry: bad args"
  167.         signal error
  168.     end
  169.     parse arg mailbox, handle
  170.  
  171.         drop log.
  172.         log. = ''
  173.  
  174.     if ~exists(mailboxDir(mailbox)) then do
  175.         call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
  176.         return
  177.     end
  178.  
  179.     opened = open(handle, logFile(mailbox, handle), 'r')
  180.         if opened then do
  181.         call showDebugger('Loading entry' logFile(mailbox, handle))
  182.         do while ~eof(handle)
  183.             line = readln(handle)
  184.             parse upper var line variable '=' value
  185.             log.variable = value
  186.         end
  187.         call close(handle)
  188.     end; else call showDebugger('Could not load' logFile(mailbox, handle))
  189.     return
  190.  
  191. /* pass a handle here */
  192. saveLogEntry: procedure expose log.
  193.     if arg() ~= 2 then do
  194.         rc = "saveLogEntry: bad args"
  195.         signal error
  196.     end
  197.     parse arg mailbox, handle
  198.  
  199.     if ~exists(mailboxDir(mailbox)) then do
  200.         call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
  201.         return
  202.     end
  203.  
  204.     opened = open(handle, logFile(mailbox, handle), 'w')
  205.  
  206.     if opened then do
  207.         call showDebugger('Saving entry' logFile(mailbox, handle))
  208.         call writeln(handle, 'TYPE=' || log.type)
  209.         call writeln(handle, 'TIME=' || log.time)
  210.         call writeln(handle, 'LENGTH=' || log.length)
  211.  
  212.         call writeln(handle, 'ORIGMAILBOX=' || log.origmailbox)
  213.  
  214.         call writeln(handle, 'CIDNAME=' || log.cidname)
  215.         call writeln(handle, 'CIDNUMBER=' || log.cidnumber)
  216.  
  217.         call writeln(handle, 'COMMENT=' || log.comment)
  218.  
  219.         call writeln(handle, 'FILENAME=' || log.filename)
  220.         call writeln(handle, 'ALTFILENAME=' || log.altfilename)
  221.  
  222.         call writeln(handle, 'RETURNNUMBER=' || log.returnnumber)
  223.         call writeln(handle, 'RETURNSENDFUNC=' || log.returnsendfunc)
  224.         call writeln(handle, 'RETURNSTATUS=' || log.returnstatus)
  225.  
  226.         call writeln(handle, 'RETURNRETRY=' || log.returnretry)
  227.         call writeln(handle, 'RETURNINTERVAL=' || log.returninterval)
  228.  
  229.         call close(handle)
  230.         address rexx 'broadcast' 'addtomailbox' mailbox handle
  231.     end; else call showDebugger('Could not save' logFile(mailbox, handle))
  232.  
  233.     return
  234.  
  235. /* pass a handle here */
  236. updateLogEntry: procedure expose log.
  237.     if arg() ~= 2 then do
  238.         rc = "updateLogEntry: bad args"
  239.         signal error
  240.     end
  241.     parse arg mailbox, handle
  242.  
  243.     if ~exists(mailboxDir(mailbox)) then do
  244.         call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
  245.         return
  246.     end
  247.  
  248.     if ~exists(logFile(mailbox, handle)) then do
  249.         call showDebugger('Unable to update non-existent' logFile(mailbox, handle))
  250.         return
  251.     end
  252.     opened = open(handle, logFile(mailbox, handle), 'w')
  253.  
  254.     if opened then do
  255.         call showDebugger('Updating entry' logFile(mailbox, handle))
  256.         call writeln(handle, 'TYPE=' || log.type)
  257.         call writeln(handle, 'TIME=' || log.time)
  258.         call writeln(handle, 'LENGTH=' || log.length)
  259.  
  260.         call writeln(handle, 'ORIGMAILBOX=' || log.origmailbox)
  261.  
  262.         call writeln(handle, 'CIDNAME=' || log.cidname)
  263.         call writeln(handle, 'CIDNUMBER=' || log.cidnumber)
  264.  
  265.         call writeln(handle, 'COMMENT=' || log.comment)
  266.  
  267.         call writeln(handle, 'FILENAME=' || log.filename)
  268.         call writeln(handle, 'ALTFILENAME=' || log.altfilename)
  269.  
  270.         call writeln(handle, 'RETURNNUMBER=' || log.returnnumber)
  271.         call writeln(handle, 'RETURNSENDFUNC=' || log.returnsendfunc)
  272.         call writeln(handle, 'RETURNSTATUS=' || log.returnstatus)
  273.  
  274.         call writeln(handle, 'RETURNRETRY=' || log.returnretry)
  275.         call writeln(handle, 'RETURNINTERVAL=' || log.returninterval)
  276.  
  277.         call close(handle)
  278.         address rexx 'broadcast' 'refreshmailboxentry' mailbox handle
  279.     end; else call showDebugger('Could not update' logFile(mailbox, handle))
  280.  
  281.     return
  282.  
  283.  
  284.  
  285. showDebugger: procedure
  286.     if arg() ~= 1 then do
  287.         say "showDebugger: ERROR"
  288.         exit 20
  289.     end
  290.  
  291.     parse arg debuggerInfo
  292.     
  293.     firstLine = sourceline(1)
  294.     parse var firstLine '/*' 'TITLE:' title '*/'
  295.     if showlist('p', 'AVMUSERINTERFACE') then
  296.         address 'AVMUSERINTERFACE' 'addlog' title ':' debuggerInfo
  297.     else
  298.         say title ':' debuggerInfo
  299.  
  300.     return 
  301.  
  302. /*-----------------------------------------------------------------------*/
  303. /*                         signal processing                             */
  304.  
  305. arexxerror:
  306. error:
  307.     call showDebugger("Error" rc "at line" sigl)
  308.     exit 20
  309.  
  310. break_c:
  311. halt:
  312.     call showDebugger("Halt/Break_C at line" sigl)
  313.     exit 20
  314.  
  315. novalue:
  316.     call showDebugger("No value at line" sigl)
  317.     exit 20
  318.  
  319. syntax:
  320.     call showDebugger("Syntax error" rc "at line" sigl)
  321.     exit 20
  322.  
  323. /* TITLE: avm:rexx/stdplayvoice.avm */
  324. stdPlayXX:
  325. procedure
  326. parse arg ret
  327.  
  328. rs.normal = 0
  329. rs.keydetected = 1
  330. rs.quietdetected = 2
  331. rs.silencedetected = 3
  332. rs.faxdetected = 4
  333. rs.datadetected = 5
  334. rs.busydetected = 8
  335. rs.timedout = 10
  336. rs.signaldetected = 12
  337. rs.overflow = 14
  338. rs.error = 16
  339. /* CB 0000 */
  340.  
  341. select
  342.   when ret=rs.faxdetected then signal stdfax
  343.   when ret=rs.datadetected then signal stddata
  344.   when ret=rs.busydetected then signal stdbusy
  345.   when ret=rs.signaldetected then signal stdabort
  346.   when ret=rs.overflow then signal stderror
  347.   when ret=rs.error then signal stderror
  348.   otherwise nop
  349. end
  350. return
  351.  
  352.  
  353. aapresentmenu:
  354. /* TITLE: avm:rexx/presentmenu.avm */
  355. procedure expose pmRetries pmTimesAround
  356. parse arg filename, valid, retries
  357. timesaround = retries
  358. pmTimesAround = timesaround
  359. pmRetries = retries
  360.  
  361. rs.normal = 0
  362. rs.keydetected = 1
  363. rs.quietdetected = 2
  364. rs.silencedetected = 3
  365. rs.faxdetected = 4
  366. rs.datadetected = 5
  367. rs.busydetected = 8
  368. rs.timedout = 10
  369. rs.signaldetected = 12
  370. rs.overflow = 14
  371. rs.error = 16
  372. /* CB 0000 */
  373.  
  374. aapresentmenuloop:
  375. 'playvoice' filename
  376. a_=rc
  377. if 0 then nop
  378. else if a_=4 then do;return rs.faxdetected;end
  379. else if a_=5 then do;return rs.datadetected;end
  380. else if a_=8 then do;return rs.busydetected;end
  381. else if a_=12 then do;return rs.signaldetected;end
  382. else if a_=14 then do;return rs.error;end
  383. else if a_=16 then do;return rs.error;end
  384.  
  385. 'readnkeys' '1' '5'
  386. a_=rc
  387. if a_=0 then value=result
  388. if 0 then nop
  389. else if a_=0 then signal aapresentmenuvalue
  390. else if a_=4 then do;return rs.faxdetected;end
  391. else if a_=5 then do;return rs.datadetected;end
  392. else if a_=8 then do;return rs.busydetected;end
  393. else if a_=10 then signal aapresentmenutimeout
  394. else if a_=12 then do;return rs.signaldetected;end
  395. else if a_=14 then do;return rs.error;end
  396. else if a_=16 then do;return rs.error;end
  397. return rs.error
  398.  
  399. aapresentmenutimeout:
  400. 'flushphonebuffer'
  401.  
  402. 'playvoice' 'avm:voices/TimedOut'
  403. a_=rc
  404. if 0 then nop
  405. else if a_=4 then do;return rs.faxdetected;end
  406. else if a_=5 then do;return rs.datadetected;end
  407. else if a_=8 then do;return rs.busydetected;end
  408. else if a_=12 then do;return rs.signaldetected;end
  409. else if a_=14 then do;return rs.error;end
  410. else if a_=16 then do;return rs.error;end
  411.  
  412. timesaround = timesaround - 1; pmTimesAround = timesaround
  413. if timesaround <= 0 then return rs.timedout
  414. signal aapresentmenuloop
  415.  
  416. aapresentmenuvalue:
  417. if pos(value, valid) = 0 then signal aainvalid
  418. return '=' || value
  419.  
  420. aainvalid:
  421. 'flushphonebuffer'
  422.  
  423. 'playvoice' 'avm:voices/BadChoice'
  424. a_=rc
  425. if 0 then nop
  426. else if a_=4 then do;return rs.faxdetected;end
  427. else if a_=5 then do;return rs.datadetected;end
  428. else if a_=8 then do;return rs.busydetected;end
  429. else if a_=12 then do;return rs.signaldetected;end
  430. else if a_=14 then do;return rs.error;end
  431. else if a_=16 then do;return rs.error;end
  432.  
  433. timesaround = timesaround - 1; pmTimesAround = timesaround
  434. if timesaround <= 0 then return rs.timedout
  435. signal aapresentmenuloop
  436.  
  437.  
  438. stdabort:
  439. exit
  440.  
  441. stdbusy:
  442. exit
  443.  
  444. stderror:
  445. exit
  446.  
  447. stdtimedout:
  448. exit
  449.  
  450. stdfaxinstruct:
  451. 'playvoice' 'avm:voices/FaxStarting'
  452. a_=rc
  453. if 0 then nop
  454. else if a_=1 then do;call checkifabort;end
  455. else if a_=8 then signal stdbusy
  456. else if a_=12 then signal stdabort
  457.  
  458. stdfax:
  459. faxscript = getclip(address() || 'FAXSCRIPT')
  460. if faxscript = '' then faxscript = 'handlefax'
  461. if symbol('mailbox') = 'VAR' then address rexx faxscript address() mailbox
  462. else address rexx faxscript address() 'anonymous'
  463. exit
  464.  
  465. stddatainstruct:
  466. 'playvoice' 'avm:voices/DataStarting'
  467. a_=rc
  468. if 0 then nop
  469. else if a_=1 then do;call checkifabort;end
  470. else if a_=8 then signal stdbusy
  471. else if a_=12 then signal stdabort
  472.  
  473. stddata:
  474. datascript = getclip(address() || 'DATASCRIPT')
  475. if datascript = '' then datascript = 'handledata'
  476. if symbol('mailbox') = 'VAR' then address rexx datascript address() mailbox
  477. else address rexx datascript address()
  478. exit
  479.  
  480. checkifabort:
  481. 'readnkeys' '1' '3'
  482. a_=rc
  483. if a_=0 then value=result
  484. if 0 then nop
  485. else if a_=0 then do;if value = '*' then signal stdabort;end
  486. else if a_=8 then signal stdbusy
  487. else if a_=12 then signal stdabort
  488. else if a_=14 then signal stderror
  489. else if a_=16 then signal stderror
  490. return
  491.  
  492.  
  493.